capture cd "D:\Dropbox\book_welfare\replication\"


import delimited data\goodreads_book_authors.json, delimiter(comma) clear



	forvalues k=1(1) 5 {
		split v`k', parse(": ")
		gen l`k'2 =length(v`k'2)
		gen a`k' = substr(v`k'2,2,length(v`k'2)-2)
	}

	rename a1 ratings_count 
	gen double author_id = real(a2)
	rename a3 text_reviews_count 
	rename a4 name 
	rename a5 reviews_count



	replace reviews_count  = substr(reviews_count,1,length(reviews_count)-1)

	keep ratings_count author_id text_reviews_count name reviews_count

	split name, parse(" ")
	rename name fullname 
	rename name1 name 


	replace name=upper(name)
	merge m:1 name using data\name_gender_wipo.dta
	drop if _merge==2 
	drop _merge 

	keep ratings_count author_id text_reviews_count fullname reviews_count mshare 


	destring ratings_count text_reviews_count reviews_count, replace 
	merge m:1 fullname using data\fullname_mshare_hand.dta
	replace mshare = mshare_hand if mshare==. & mshare_hand~=.
	drop mshare_hand _merge 

save  data\author.dta, replace 

